package com.android.music.prolyric;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class setting_background extends Activity
{
	Integer[] imagesIDs = {
			R.drawable.bgr1,
			R.drawable.bgr2,
			R.drawable.bgr3,
			
			R.drawable.bgr5,
			
			R.drawable.bgr7,
			R.drawable.lib,
			R.drawable.lib1,
			R.drawable.lib2,
			R.drawable.lib3,
			R.drawable.lip3,
			
			R.drawable.girl
			
			};
	int size = imagesIDs.length,count=0;
	private GridView gridview;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting_background);
		gridview	= (GridView)findViewById(R.id.gvBackground);
        gridview.setAdapter(new ImageAdapter(this));
        gridview.setOnItemClickListener(new OnItemClickListener() 
        {
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) 
			{
				Log.i("select", arg2+"");
				Intent data = new Intent();
				data.setData(Uri.parse(imagesIDs[arg2]+""));
				setResult(RESULT_OK, data);
				finish();				
			}	
        	
		});
	}	
	
	public class ImageAdapter extends BaseAdapter
    {
    	private Context context;
    	
    	public ImageAdapter(Context c)
    	{
    		context=c;
    	}
		public int getCount() 
		{
			return imagesIDs.length;
		}

		public Object getItem(int position) 
		{
			return position;
		}

		public long getItemId(int position) 
		{
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) 
		{
			ImageView imageView;
			if(convertView==null)
			{
				imageView = new ImageView(context);
				imageView.setLayoutParams(new GridView.LayoutParams(100,100));
				imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
				imageView.setPadding(5,5,5,5);
			}
			
			else
			{
				imageView = (ImageView)convertView;
			}
			
			imageView.setImageResource(imagesIDs[position]);
			return imageView;
		}
    	
    }
	

}
